<?php namespace Common\Model;
use Hdphp\Model\Model;
class User extends Model{
	protected $table='user';
	protected $validate=array(
			array('username','required','请填写用户名',3,3),
			array('username','minlen:8','用户名不得小于8位',3,3),
			array('usernick','minlen:3','用户昵称不得小于3个字符',3,3),
			array('usernick','_usernick','昵称已被占用',3,3),
			array('password','required','请填写密码',3,3),
			array('password','minlen:6','密码不得小于6位',3,3),
			array('confirmpassword','required','请确认您的密码',3,3),
			array('confirmpasswird','_confirmpassword','两次密码输入不一致',3,3),
			array('code','required','请填写验证码',3,3),
			array('code','_code','验证码不正确',3,3),
			array('username','_username','用户名已存在',3,3),
			
	);
	protected $auto = array(
       array('password','md5','function',3,3)
    );
	
	public function _code(){
		$code=Q('post.code');
		if(strtolower($code)!=strtolower($_SESSION['code'])) return false;
		return true;
	}
//	判断用户名是否存在
	 public function _username(){
        $username = Q('post.username');
        $data = $this->where("username='{$username}'")->find();
        if($data) return false;
        return true;
    }
//判断昵称是否存在	 
	 public function _usernick(){
	 	$usernick=Q('post.usernick');
		$nickdata=$this->where("usernick='{$usernick}'")->find();
		if($nickdata)return false;
		return true;
	 }
	 
	 public function _confirmpassword(){
	 	$data=Q('post.');
		if($data['confirmpassword']!=$data['password']) return false;
		  return true;
			
		
	 }
	
	public function store(){
		if(!$this->create()) return false;		
			if($this->data['sex']==1){
				$this->data['sex']='女';
			}else{
				$this->data['sex']='男';
			}
		$this->add();
		return true;
	}
}
